package at.fhooe.mc.android.shiftalarmclock;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.NumberPicker;
import android.widget.TimePicker;

public class SettingsTier extends Activity {

	@SuppressWarnings("static-access")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.set_tier);
		super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

		// array to store
		final String[] data = new String[3];

		
		// get Shift
		final NumberPicker ShiftPicker = (NumberPicker) findViewById(R.id.ShiftPicker);
		ShiftPicker.setMinValue(0);
		ShiftPicker.setMaxValue(3);
		ShiftPicker.setDisplayedValues(new String[] {
				getResources().getString(R.string.early),
				getResources().getString(R.string.midday),
				getResources().getString(R.string.evening),
				getResources().getString(R.string.free) });
		// disable "keyboard"
		ShiftPicker
				.setDescendantFocusability(ShiftPicker.FOCUS_BLOCK_DESCENDANTS);

		// get Time
		final TimePicker tp = (TimePicker) findViewById(R.id.timePicker1);
		tp.setIs24HourView(true);

		// Number Picker, how often
		final NumberPicker nPicker = (NumberPicker) findViewById(R.id.numberPicker3);
		nPicker.setMinValue(1);
		nPicker.setMaxValue(7);

		// save data
		Button bSet = (Button) findViewById(R.id.button1);
		bSet.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View _v) {
				// get shift
				switch (ShiftPicker.getValue()) {
				case 0: {
					data[0] = getResources().getString(R.string.early);
				}
					break;
				case 1: {
					data[0] = getResources().getString(R.string.midday);
				}
					break;
				case 2: {
					data[0] = getResources().getString(R.string.evening);
				}
					break;
				case 3: {
					data[0] = getResources().getString(R.string.free);
				}
					break;
				}

				// get Time
				if (ShiftPicker.getValue() == 3) {
					data[1] = "";
				} else {
					String min = tp.getCurrentMinute().toString();
					if(min.length() == 1) {
						data[1] = tp.getCurrentHour() + ":0" + tp.getCurrentMinute();
					} else {
						data[1] = tp.getCurrentHour() + ":" + tp.getCurrentMinute();
					}
				}

				// get how often
				data[2] = Integer.toString(nPicker.getValue());

				// commit
				DummyData next = new DummyData(data[0], data[1], data[2]);
				MainActivity.list.add(next);
				
				DummyDataMain next2 = new DummyDataMain(data[0], data[1]);
				for (int i = 0; i < nPicker.getValue(); i++) {
					MainActivity.listMain.add(next2);
				}
				

//				// Toast to control
//				Toast.makeText(
//						SettingsTier.this,
//						"User has selected " + data[0] + " " + data[1]
//								+ " for " + data[2] + " time",
//						Toast.LENGTH_LONG).show();

				finish();// move to previous activity
			}
		});
	}
}